package com.example.easycharge.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.easycharge.entity.ChargePile;
import com.example.easycharge.entity.Report;
import com.example.easycharge.notRepEntity.WaitAreaMonitor;
import com.example.easycharge.repository.ChargePileRepository;
import com.example.easycharge.repository.ReportRepository;
import com.example.easycharge.service.ChargeService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("report")
public class ReportController {

    @Autowired
    private ReportRepository reportRepository;
    @Autowired
    private ChargePileRepository chargePileRepository;
    @Autowired
    private ChargeService chargeService;

    // 查看某天的全部报表
    @GetMapping("/admin/{checkDate}")
    public List<Report> getReports(@PathVariable String checkDate) {
        return reportRepository.findByRecordDate(checkDate);
    }

    @GetMapping("/admin/{checkDate}/{pileId}")
    public Report getPileReport(@PathVariable String checkDate, @PathVariable long pileId) {
        // 查看某天某个充电桩的全部报表
        return reportRepository.findReportByRecordDateAndPileId(checkDate, pileId);
    }

    @GetMapping("/admin/realTime")
    public List<Report> getRealTimeReports() {
        List<ChargePile> allPile = chargePileRepository.findAll();
        List<Report> reportList = new ArrayList<>(allPile.size());
        for (ChargePile chargePile : allPile) {
            reportList.add(new Report(chargePile));
        }
        return reportList;
    }

    @Operation(description = "监控等候区")
    @GetMapping("/area")
    public WaitAreaMonitor monitorArea() {
        return chargeService.waitAreaMonitor();
    }
}
